package com.xzc.jcip._2_.线程安全性问题;

import net.jcip.annotations.NotThreadSafe;

import static java.lang.Thread.sleep;

@NotThreadSafe
public class UnsafeSequence {
    private int value;

    public int getNext() {
        return value++;
    }

    public static void main(String[] args) {
        UnsafeSequence unsafeSequence = new UnsafeSequence();
        for (int i = 0; i < 3; i++) {
            int finalI = i;
            new Thread(() -> {
                while (true) {
                    System.out.println("t" + finalI + "=>" + unsafeSequence.getNext());
                    try {
                        sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }
    }
}
